package com.company.cloud.product.modules.mgr.utils;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.CollectionUtils;

import com.company.cloud.common.utils.StrSplitUtils;
import com.company.cloud.product.modules.api.response.ProductSkuSpecificationItem;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;

public class ProductSnUtils {

	
	public static String getProductSN() {
		return StrUtil.format("P{}", IdUtil.getSnowflake(4, 1).nextIdStr());
	}
	
	public static String getProductRelId() {
		return StrUtil.format("PL{}", IdUtil.getSnowflake(4, 5).nextIdStr());
	}
	
	public static String getSkuSN() {
		return StrUtil.format("SKU{}", IdUtil.getSnowflake(4, 2).nextIdStr());
	}
	
	public static String getComeSN() {
		return StrUtil.format("COME_{}", IdUtil.getSnowflake(4, 3).nextIdStr());
	}
	
	public static String getOutSN() {
		return StrUtil.format("OUT_{}", IdUtil.getSnowflake(4, 4).nextIdStr());
	}
	
	public static String getSkuSN(String productNo,List<ProductSkuSpecificationItem> items) {
		StringBuilder str=new StringBuilder();
		str.append(productNo);
		if(!CollectionUtils.isEmpty(items)) {
			items.sort((a,b) -> a.getName().compareTo(b.getName()));
			items.forEach(item->{
				str.append(item.getValue());
			});
		}
		System.out.println(str.toString());
		int i= Math.abs(str.toString().hashCode());
		return "SKU"+i;
	}
	
	public static void main(String[] args) {
//		ProductSkuSpecificationItem item1=new ProductSkuSpecificationItem("颜色", "黑色");
//		ProductSkuSpecificationItem item2=new ProductSkuSpecificationItem("内存", "16G");
//		ProductSkuSpecificationItem item3=new ProductSkuSpecificationItem("屏幕", "5.5");
//		ProductSkuSpecificationItem item4=new ProductSkuSpecificationItem("网络", "5G");
//		
//		List<ProductSkuSpecificationItem> items=new ArrayList<ProductSkuSpecificationItem>();
//		items.add(item2);
//		items.add(item3);
//		items.add(item4);
//		items.add(item1);
//		
//		System.out.println(getSkuSN("p1000", items));
	
	 List<String> names= StrSplitUtils.parse2list("cdt,edt,name,orders,price,product_no", String.class);
		
	  for (int i = 0; i < 50; i++) {
		  System.out.println( names.get(RandomUtil.randomInt(0, 6)));
	  }
		
		
		
	}
	
	
}
